<?php
error_reporting(E_ALL);
$relPath = "./pinc/";
require_once $relPath."dpinit.php";
include_once($relPath.'dp_main.inc');

$jq             = Arg("jsonqry");
$jq             = rawurldecode($jq);
$json           = json_decode(rawurldecode(Arg("jsonqry")));

if(! is_object($json)) {
    LogMsg("wc: json not-an-object error: {$json}");
    echo "not an object :: $jq";
    exit;
}

$querycode          = $json->querycode;
$sessionid          = $json->sessionid;
$token              = $json->token;

switch($querycode) {
    case "authorize":
        $user       = new DpSessionUser($sessionid);
        $a          = array();
        $a = array("querycode" => $querycode,
                    "token"     => $token);
        $a["username"] = $user->Username();
        json_echo($a);
        exit;
}

function json_echo($rsp) {
    $rsp = json_encode($rsp);
    $rsp = rawurlencode($rsp);
    echo $rsp;
}
?>
